From a40a89dbc2feb33cb30cedcb683c14839a13cb8e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Tue, 5 Sep 2017 03:36:22 +0200 Subject: [PATCH] babl: bail early on paths that are bad ideas Not going through/bench-marking chains that will make the number of components drop below the input/output counts, and not permitting a temporary lack of alpha both fixes bugs at higher tolerances and speeds up path selection. --- babl/babl-fish-path.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c index a383b14..3c0eb6a 100644 --- a/babl/babl-fish-path.c +++ b/babl/babl-fish-path.c @@ -151,6 +151,24 @@ int _babl_max_path_len (void) return max_path_length (); } +static int +bad_idea (const Babl *from, const Babl *to, const Babl *format) +{ + if (babl_format_has_alpha (from) && + babl_format_has_alpha (to) && + !babl_format_has_alpha (format)) + { + return 1; + } + if (from->format.components > format->format.components && + to->format.components > format->format.components) + { + return 1; + } + return 0; +} + + /* The task of BablFishPath construction is to compute * the shortest path in a graph where formats are the vertices * and conversions are the edges. However, there is an additional @@ -164,7 +182,6 @@ int _babl_max_path_len (void) * implemented by recursive function get_conversion_path (). */ - static void get_conversion_path (PathContext *pc, Babl *current_format, @@ -185,7 +202,7 @@ get_conversion_path (PathContext *pc, double path_cost = 0.0; double ref_cost = 0.0; double path_error = 1.0; -#if 1 +#if 0 int i; for (i = 0; i < babl_list_size (pc->current_path); i++) { @@ -248,7 +265,7 @@ get_conversion_path (PathContext *pc, { Babl *next_conversion = BABL (list->items[i]); Babl *next_format = BABL (next_conversion->conversion.destination); - if (!next_format->format.visited) + if (!next_format->format.visited && !bad_idea (current_format, pc->to_format, next_format)) { /* next_format is not in the current path, we can pay a visit */ babl_list_insert_last (pc->current_path, next_conversion); -- 2.30.2